﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using MTGenome.MTG;

namespace MTGenome.Gatherer
{
    [Export(typeof(IDeckLoader)), PartCreationPolicy(CreationPolicy.Shared)]
    public sealed class DeckLoader : IDeckLoader
    {
        private static readonly XmlSerializer _serializer = new XmlSerializer(typeof(Deck));

        public void Save(IDeck deck, string path)
        {
            using (FileStream stream = File.Create(path))
            {
                _serializer.Serialize(stream, deck as Deck);
            }
        }

        public IDeck Load(string path)
        {
            using (FileStream stream = File.OpenRead(path))
            {
                return (Deck)_serializer.Deserialize(stream);
            }
        }
    }
}
